﻿<Window 
    x:Class="MyWpfControlsTestBench.Demos.TreeViewDemoWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:viewModel="clr-namespace:Gonte.Wpf.Controls.ViewModel;assembly=MyWpfControls"
    Title="TreeView Demo" 
    Height="400" 
    Width="180">
    
    <Grid>

        <TreeView ItemsSource="{Binding This}" 
                  SelectedItemChanged="OnTreeViewSelectedItemChanged" 
                  Name="demoTreeView"
                  >

            <TreeView.ItemContainerStyle>

                <Style TargetType="{x:Type TreeViewItem}">

                    <EventSetter
                        Event="TreeViewItem.MouseRightButtonDown"
                        Handler="OnTreeViewItemMouseRightButtonDown"/>

                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                    <Setter Property="FontWeight" Value="Normal" />

                    <Style.Triggers>

                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>

                    </Style.Triggers>

                </Style>

            </TreeView.ItemContainerStyle>

            <TreeView.Resources>

                <HierarchicalDataTemplate 
                  DataType="{x:Type viewModel:ViewModelBase}" 
                  ItemsSource="{Binding Children}"
                  >

                    <StackPanel Orientation="Horizontal">

                        <Image Width="16" Height="16" Margin="3,0" Source="{Binding IconSource}" />
                        <TextBlock Text="{Binding Label}" />

                    </StackPanel>

                </HierarchicalDataTemplate>

            </TreeView.Resources>

        </TreeView>

    </Grid>

</Window>
